'use strict';
new Component({
  options: {
    addGlobalClass: true,
  },
  externalClasses: ['lee-class'],
  data: {
    show: false,
    options: {},
  },
  methods: {
    open() {
      this.setData({ show: true });
    },
    close() {
      this.setData({ show: false });
    },
    init(options = {}, show = true) {
      this.setData({ options }, () => {
        if (show) this.setData({ show });
      });
    },
    onClick(e) {
      const { index } = e.currentTarget.dataset;
      const item = this.data.options.buttons[index];
      if (item && typeof this.data.options.buttonClicked === 'function') {
        this.data.options.buttonClicked({ item, index });
      }
      this.close();
    },
  },
});
